package com.hzgj.soa.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/8/12.
 */
@Component
public class UserClient {
    static int count = 0;
    @Autowired
    private UserService userService;
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private UserIdempotentIdGen userIdempotentIdGen;

    public void login() {
        for (int i = 0; i < 1; i++) {
            new Thread(() -> {
                int j = 5;
                while (j-- > 0) {
                    try {
//                        userService.login(User.builder().
//                                name("User_" + ThreadLocalRandom.current().nextInt(100)).build());
                        TimeUnit.SECONDS.sleep(2);
                        long start = System.currentTimeMillis();
//                        if (count < 10) {
                        userIdempotentIdGen.setContinueId(new Random().nextFloat() + "");
                        userService.sendFlower(1);
                        System.out.println("spend time=" + (System.currentTimeMillis() - start));
//                            count++;
//                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }
}
